package com.hissy.common.chain;

import java.util.Arrays;
import java.util.List;

import com.hissy.common.chain.Scope.ScopeBuilder;
import org.junit.Test;

/**
 * Created by zhangyanfei on 2018/12/27.
 * 责任链+策略模式
 *
 * @author zhangyanfei
 * @date 2018/12/27
 */
public class HandleChain {
    public void handle(Scope scope) {
        AHandle aHandle = new AHandle();
        BHandle bHandle = new BHandle();
        CHandle cHandle = new CHandle();

        List<Handle> handleList = Arrays.asList(aHandle, bHandle, cHandle);

        for (Handle handle : handleList) {
            if (handle.isExtend(scope)) {
                handle.action();
            }
        }
    }

    @Test
    public void test_C1() {
        HandleChain handleFactory = new HandleChain();
        Scope scopeBuilder = new ScopeBuilder().extend(Scope.A_SCOPE).extend(Scope.C_SCOPE).extend(Scope.B_SCOPE)
            .build();
        handleFactory.handle(scopeBuilder);
    }
}
